package com.ch.base.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

public class PaginationCheckboxTag extends TagSupport{
	private final Logger log = Logger.getLogger(this.getClass());
	
	private String paginationType;
	private String chkType;
	private String targetObjId;
	private String returnChkId;
	private String chkAllObjId;
	private String chkObjName;
	private String title = "";
	private String onclick;
	private String value;
	private int row;
	
	public int doStartTag() throws JspException{
		JspWriter out = pageContext.getOut();
		try{
			if(chkType.equals("chkAll")){
				out.println("<input type=\"checkbox\" id=\"" + chkAllObjId+ "\" onclick=\"chkAll(this, '" + paginationType + "', '" + targetObjId + "', " + returnChkId + ", '" + chkObjName + "');" + onclick + "\" title=\"" + title + "\" />");
			}else if(chkType.equals("chk")){
				int pageSize = (Integer) pageContext.getRequest().getAttribute("pageSize");
				int currentPage = (Integer) pageContext.getRequest().getAttribute("currentPage");
				int realRow = pageSize * (currentPage - 1) + row;
				out.println("<input type=\"checkbox\" id=\"" + chkObjName + "_" + realRow + "\" name=\"" + chkObjName + "\" value=\"" + value + "\" onclick=\"chk(this, '" + paginationType + "', '" + targetObjId + "', " + returnChkId + ", '" + chkAllObjId + "');" + onclick + "\" title=\"" + title + "\" />");
			}
		}catch(Exception ex){
			throw new JspException(ex);
		}
		return EVAL_BODY_INCLUDE;
	}

	public int doEndTag() throws JspException {
		JspWriter out = pageContext.getOut();
		try{
			
		}catch(Exception ex){
			throw new JspException(ex);
		}
		this.release();
		return EVAL_PAGE;
	}

	public String getPaginationType() {
		return paginationType;
	}

	public void setPaginationType(String paginationType) {
		this.paginationType = paginationType;
	}

	public String getChkType() {
		return chkType;
	}

	public void setChkType(String chkType) {
		this.chkType = chkType;
	}

	public String getTargetObjId() {
		return targetObjId;
	}

	public void setTargetObjId(String targetObjId) {
		this.targetObjId = targetObjId;
	}

	public String getReturnChkId() {
		return returnChkId;
	}

	public void setReturnChkId(String returnChkId) {
		this.returnChkId = returnChkId;
	}

	public String getChkAllObjId() {
		return chkAllObjId;
	}

	public void setChkAllObjId(String chkAllObjId) {
		this.chkAllObjId = chkAllObjId;
	}

	public String getChkObjName() {
		return chkObjName;
	}

	public void setChkObjName(String chkObjName) {
		this.chkObjName = chkObjName;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public Logger getLog() {
		return log;
	}
	
	
}
